import { getItem, setItem } from '@/utils/auth.js'
import { userProfile } from '@/api/user.js'

const state = {
  token: getItem() || '',
  userInfo: ''
}
const mutations = {
  setToken (state, value) {
    state.token = value
    setItem(value)
  },
  setUserInfo (state, value) {
    state.userInfo = value
  },
  setUserOther (state, value) {
    state.userInfo[value.key] = value.value
  }
}
const getters = {
  getToken () {
    return state.token
  }
}
const actions = {
  getStore (store) {},

  async getUserInfo (store) {
    if (store.state.userInfo === '') {
      const res = await userProfile()
      console.log('用户个人信息', res)
      store.commit('setUserInfo', res.data)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  getters,
  actions
}
